package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.*;
import com.acme.service.NeatPrinter;

/**
 * Bank service class.
 * 
 */
public class BankService {
	private static final int START_NUMBERING_FROM = 1;
	
	private static final String ACCOUNT_LIST_TITLE = "ACCOUNT LIST";
	private static final String BALANCE_TITLE = "BALANCE";
	private static final String MAX_AMOUNT_TO_WITHDRAW_TITLE = "MAX. AMOUNT TO WITHDRAW";
	private static final String CLIENT_LIST_TITLE = "CLIENT LIST";

	/**
	 * Prints balance for every account of every client of the bank.
	 * 
	 * @param bank
	 *            bank
	 */
	public static void printBalance(Bank bank) {
		NeatPrinter.printTitle(BALANCE_TITLE);
		for (Client client : bank.getClients()) {
			System.out.println("*** Client " + client.getClientSalutation()
					+ " ***");
			for (Account account : client.getAccounts()) {
				System.out.println(" Balance $: " + account.getBalance());
			}
		}
		System.out.println();
	}

	/**
	 * Prints maximum amount to withdraw for every account of every client of
	 * the bank.
	 * 
	 * @param bank
	 *            bank
	 */
	public static void printMaximumAmountToWithdraw(Bank bank) {
		NeatPrinter.printTitle(MAX_AMOUNT_TO_WITHDRAW_TITLE);
		for (Client client : bank.getClients()) {
			System.out.println("*** Client " + client.getClientSalutation()
					+ " ***");
			for (Account account : client.getAccounts()) {
				System.out.println(" Max. amount to withdraw $: "
						+ account.maximumAmountToWithdraw());
			}
		}
		System.out.println();
	}

	/**
	 * Prints all bank's clients.
	 * 
	 * @param bank
	 *            bank
	 */
	public static void printAllClients(Bank bank) {
		NeatPrinter.printTitle(CLIENT_LIST_TITLE);
		int number = START_NUMBERING_FROM;
		for (Client client : bank.getClients()) {
			System.out.println(number + ". " + client.getClientSalutation());
			number++;
		}
		System.out.println();
	}

	/**
	 * Print all bank's accounts.
	 * 
	 * @param bank
	 *            bank
	 */
	public static void printAllAccounts(Bank bank) {
		NeatPrinter.printTitle(ACCOUNT_LIST_TITLE);
		int number = START_NUMBERING_FROM;
		for (Account account : bank.getAccounts()) {
			System.out.println(number + ". Balance: " + account.getBalance()
					+ ", max. amount to withdraw: "
					+ account.maximumAmountToWithdraw());
			number++;
		}
		System.out.println();
	}

	/**
	 * Adds client to the bank.
	 * 
	 * @deprecated Add clients to the bank instance directly instead of using
	 *             this method.
	 * 
	 * @param bank
	 *            bank
	 * @param client
	 *            client to add
	 */
	@Deprecated
	public static void addClient(Bank bank, Client client) {
		bank.addClient(client);
	}
}
